﻿using System;
using System.Linq;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 添加产品
    /// </summary>
    public partial class AddProduct : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object result;
            try
            {

                var name = Fq("CoName").SafeToString();
                var nameEn = Fq("CoNameEn").SafeToString();
                var description = Fq("CoDescription").SafeToString();
                var descriptionEn = Fq("CoDescriptionEn").SafeToString();
                var productCategoryId = Fq("CoProductCategoryId").SafeToInt();
                var coverProductImageId = Fq("CoCoverImageId").SafeToInt();
                var isRecommend = Fq("CoIsRecommend").SafeToBool();
                var model = Fq("CoModel").SafeToString();
                string keyword = Fq("CoKeyword").SafeToString(),
                       keywordEn = Fq("CoKeywordEn").SafeToString(),
                       finish = Fq("CoFinish").SafeToString(),
                       finishEn = Fq("CoFinishEn").SafeToString(),
                       material = Fq("CoMaterial").SafeToString(),
                       materialEn = Fq("CoMaterialEn").SafeToString(),
                       doorThickness = Fq("CoDoorThickness").SafeToString(),
                       backset = Fq("CoBackset").SafeToString(),
                       availableFor = Fq("CoAvailableFor").SafeToString(),
                       availableForEn = Fq("CoAvailableForEn").SafeToString(),
                       applicableStandard = Fq("CoApplicableStndard").SafeToString(),
                        size = Fq("CoSize").SafeToString(),
                        modelEn = Fq("CoModelEn").SafeToString();
                var summary = Fq("CoSummary").SafeToString();
                var summaryEn = Fq("CoSummaryEn").SafeToString();
                var productImageIds = Fq("CoProductImageId").SafeToString().Split(',').Select(o => o.SafeToInt()).ToArray();
                var productService = new ProductService();
                productService.Add(name, nameEn, productCategoryId, description, descriptionEn, model, isRecommend, productImageIds, coverProductImageId, keyword, keywordEn, finish, finishEn, material, materialEn, doorThickness, backset, availableFor, availableForEn, applicableStandard, size, modelEn, summary, summaryEn);
                result = new { state = true, message = "添加成功" };
            }
            catch (Exception ex)
            {
                result = new { state = false, message = ex.Message };
            }
            Json(result);
        }
    }
}